import java.util.Scanner;

public class MaxSubarraySum {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入整数数组（空格分隔）：");
        String input = scanner.nextLine();
        String[] parts = input.split(" ");
        int[] nums = new int[parts.length];
        
        // 将字符串数组转换为整数数组
        for (int i = 0; i < parts.length; i++) {
            nums[i] = Integer.parseInt(parts[i]);
        }

        // Kadane算法实现
        int maxSoFar = nums[0];
        int maxEndingHere = nums[0];
        
        for (int i = 1; i < nums.length; i++) {
            maxEndingHere = Math.max(nums[i], maxEndingHere + nums[i]);
            maxSoFar = Math.max(maxSoFar, maxEndingHere);
        }

        System.out.println("最大子数组和为：" + maxSoFar);
    }
}